package com.winter.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.winter.mapper.DictEntryMapper;
import com.winter.model.DictEntry;
import com.winter.model.vo.response.DictEntryResponseVo;
import com.winter.util.Result;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class DictEntryService {

    @Autowired
    public DictEntryMapper dictEntryMapper;


    /**
     * 通过type获取指定字典列表
     */
    public Result dictionariesList(String type) {
        List<DictEntryResponseVo> collect = dictEntryMapper.dictionariesList(type)
                                                           .stream()
                                                           .map(f -> DictEntryResponseVo.fromDictEntry(f))
                                                           .collect(Collectors.toList());
        return Result.success(collect);
    }

    /**
     * 获取字典分类
     */
    public Result queryIndustry(String name) {
        List<DictEntry> dictEntries = dictEntryMapper.queryIndustry(name);
        return Result.success(dictEntries);
    }
}
